<!-- *************
 *@description:权限管理
 *@author:rennan
 *@date: 2023-04-02 14:12:57
 *@version: V1.0.0
 ************ -->
<template>
  <Card>
    <div class="auth_box">
      <div class="header">
        <div class="btn">
          <el-button size="mini" @click="showAdd">添加</el-button>
        </div>
      </div>
      <div class="content">
        <el-table
          :data="tableData"
          size="small"
          row-key="id"
          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
          style="width: 100%">
          <el-table-column
            label="名称"
            prop="name">
          </el-table-column>
          <el-table-column
            label="路径"
            prop="route">
          </el-table-column>
          <el-table-column
            label="类型"
            prop="type">
          </el-table-column>
          <el-table-column
            label="序号"
            prop="num">
          </el-table-column>
          <el-table-column
            label="图标"
            prop="icon">
          </el-table-column>
          <el-table-column
            label="状态">
            <template slot-scope="scope">
              <el-tag type="success" size="mini" effect="dark" v-if="scope.row.status == '显示'">{{ scope.row.status }}</el-tag>
              <el-tag type="warning" size="mini" effect="dark" v-else>{{ scope.row.status }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            fixed="right"
            label="操作"
            width="100">
            <template slot-scope="scope">
              <el-button class="columnBtn1" type="text" size="small" @click="del(scope.row)">删除</el-button>
              <el-button class="columnBtn2" type="text" size="small" @click="edit(scope.row)">编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!-- dialog -->
      <el-dialog :title="title" :visible.sync="dialogFormVisible">
        <el-form :model="form">
          <el-form-item label="名称">
            <el-input v-model="form.name" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="路径">
            <el-input v-model="form.route" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="类型">
            <el-input v-model="form.type" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="图标">
            <el-input v-model="form.icon" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="活动状态区域">
            <el-select v-model="form.status" placeholder="请选择状态">
              <el-option label="显示" value="显示"></el-option>
              <el-option label="隐藏" value="隐藏"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="addauth">确 定</el-button>
        </div>
      </el-dialog>
    </div>
  </Card>
</template>

<script>
import Card from '@/components/Card/index.vue'
import instance from '@/utils/instance';
export default {
  data(){
    return {
      tableData:[],
      title:'',
      form:{},
      dialogFormVisible:false
    }
  },
  methods:{
    getlist(){
      instance.get('/menus/list').then(res=>{
        this.tableData = res.data.data
      })
    },
    // 删除
    del(scope){

    },
    // 编辑
    edit(scope){

    },
    addauth(){
      instance.post('/menus/add',this.form).then(res=>{
        console.log(res);
        this.getlist()
        this.dialogFormVisible = false
      })
    },
    // 注意：用户是不会去操作权限的，添加了也没有对应的路由规则
    showAdd(){
      this.title = '添加权限'
      this.dialogFormVisible = true
      this.form = {}
    }
  },
  created(){
    this.getlist()
  },
  components:{
    Card
  }
}
</script>

<style lang="less" scoped>


.card_box[data-v-a53d947a]{
  overflow: hidden;
}
</style>
